﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Box2D.XNA;
using ElementumForever.Interfaces;

namespace ElementumForever
{
  public class PhysicalConnectorManager : IUpdateHandler
    {

        private List<PhysicalConnector> _connectors = new List<PhysicalConnector>();

        public void OnUpdate(GameTime gameTime) {
            foreach (PhysicalConnector physicalConnector in _connectors)
            {
                physicalConnector.OnUpdate(gameTime);
            }
        }

        public void Add(PhysicalConnector connector) {
            _connectors.Add(connector);
        }

        public bool Remove(PhysicalConnector connector) {
            return _connectors.Remove(connector);
        }

        public Body FindBodyByShape(IShape shape) {
            foreach (PhysicalConnector physicalConnector in _connectors)
            {
                if (physicalConnector.Shape == shape)
                    return physicalConnector.Body;
            }
            return null;
        }

        public IShape FindShapeByBody(Body body) {
            foreach (PhysicalConnector physicalConnector in _connectors)
            {
                if (physicalConnector.Body == body)
                    return physicalConnector.Shape;
            }
            return null;
        }
    }
}
